<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  header("location:checklogin.php");
}

$branchArray = array();
if(isset($_POST['submit']))
{  
  $branch         = (isset($_POST['branch'])) && ($_POST['branch'] != "") ? $_POST['branch'] : "" ;
  $branchCompany  = (isset($_POST['branchCompany'])) && ($_POST['branchCompany'] != "") ? $_POST['branchCompany'] : "" ;
  $licenceNo      = (isset($_POST['licenceNo'])) && ($_POST['licenceNo'] != "") ? $_POST['licenceNo'] : "" ;
  
  $insertBranch = "INSERT INTO branch (branchName,branchCompany,licenceNo)
                            VALUES('".$branch."','".$branchCompany."','".$licenceNo."')";
  $insertBranchResult = mysql_query($insertBranch);
  if(!$insertBranchResult)
    die("Insert Query Not Inserted : ".mysql_error());
  else
  {
    //header("Location:branch.php");
  }
}
  $i=0;
  $selectBranch = "SELECT  branchId,branchName,branchCompany,licenceNo
                      FROM branch
                     ORDER BY branchName";
  $selectBranchResult = mysql_query($selectBranch);
  while($branchRow = mysql_fetch_array($selectBranchResult))
  {
    $branchArray[$i]['branchId']       = $branchRow['branchId'];
    $branchArray[$i]['branchName']     = $branchRow['branchName'];
    $branchArray[$i]['branchCompany']  = $branchRow['branchCompany'];
    $branchArray[$i]['licenceNo']      = $branchRow['licenceNo'];
    $i++;
  }
include("./bottom.php");
$smarty->assign("branchArray",$branchArray);  
$smarty->display('branch.tpl');
?>